package com.zbkj.crmeb.merchant.admin.controller;


import com.common.CommonPage;
import com.crmeb.core.common.CommonResult;
import com.github.pagehelper.PageInfo;
import com.zbkj.crmeb.chant.model.ChannelPicking;
import com.zbkj.crmeb.chant.request.PickingListRequest;
import com.zbkj.crmeb.chant.request.PickingProductsRequest;
import com.zbkj.crmeb.chant.request.SavePickingRequest;
import com.zbkj.crmeb.chant.response.PickingProductResponse;
import com.zbkj.crmeb.chant.service.ChannelPickingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 商户批采单表 前端控制器
 * </p>
 *
 * @author wuzp
 * @since 2022-05-19
 */
@RestController
@RequestMapping("/api/admin/mer/picking")
@Api(tags = "商户后台-批采单管理")
public class MerChannelPickingController extends AdminBaseController {

    @Autowired
    ChannelPickingService channelPickingService;

    @ApiOperation(value = "批采单分页列表")
    @GetMapping(value = "/list")
    public CommonResult<CommonPage<ChannelPicking>> getMerPickingList(PickingListRequest request, HttpServletRequest servletRequest){
        PageInfo<ChannelPicking> pageInfo = channelPickingService.getMerPickingList(request,getMerId(servletRequest));
        return CommonResult.success(CommonPage.restPage(pageInfo));
    }

    @ApiOperation(value = "新增编辑批采单")
    @PostMapping(value = "/save")
    public CommonResult<String> savePicking(@RequestBody @Validated SavePickingRequest request, HttpServletRequest servletRequest){
        request.setMerId(getMerId(servletRequest));
        return channelPickingService.savePicking(request);
    }

    @ApiOperation(value = "删除批采单")
    @DeleteMapping(value = "/delete/{id}")
    public CommonResult<String> deletePicking(@PathVariable("id") Integer id, HttpServletRequest servletRequest){
        return channelPickingService.deletePicking(id,getMerId(servletRequest));
    }

    @ApiOperation(value = "查看商品")
    @GetMapping(value = "/products")
    public CommonResult<CommonPage<PickingProductResponse>> getProducts(@Validated PickingProductsRequest request, HttpServletRequest servletRequest){
        request.setMerId(getMerId(servletRequest));
        PageInfo<PickingProductResponse> pageInfo = channelPickingService.getProducts(request);
        return CommonResult.success(CommonPage.restPage(pageInfo));
    }

    @ApiOperation(value = "批采单下拉列表")
    @GetMapping(value = "/list/drop")
    public CommonResult<List<ChannelPicking>> getMerPickingDropList(@ApiParam(value = "下拉条件 0展示  1加入", required = true) Integer type, HttpServletRequest servletRequest){
        List<ChannelPicking> list = channelPickingService.getMerPickingDropList(type,getMerId(servletRequest));
        return CommonResult.success(list);
    }

}

